package druidTest;


import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class Demo01
{
	@Test
	public void getConnect() throws Exception
	{
		//需要使用prop对象读取配置文件
		Properties prop = new Properties();
		prop.load(new FileInputStream("./src/mysql.properties"));
		DataSource ds = DruidDataSourceFactory.createDataSource(prop);
		//获取连接对象
		Connection conn = ds.getConnection();
		//编写sql语句
		String select = "select * from emp";
		//执行sql语句
		Statement stmt = conn.createStatement();
		ResultSet rs = stmt.executeQuery(select);
		while(rs.next())
		{
			System.out.printf("%06d ",rs.getInt("empno"));
			System.out.print(rs.getString("ename") + " ");
			System.out.print(rs.getString("job") + " ");
			System.out.print(rs.getString("mgr") + " ");
			System.out.print(rs.getDate("hiredate") + " ");
			System.out.print(rs.getDouble("sal") + " ");
			System.out.print(rs.getDouble("comm") + " ");
			System.out.print(rs.getInt("deptno") + " ");
			System.out.println();
		}
		stmt.close();
		conn.close();
	}

}
